package com.next.aappublicapp.adapters;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

import com.google.android.youtube.player.YouTubePlayerFragment;
import com.next.aap.client.BaseItem;
import com.next.aappublicapp.R;
import com.next.aappublicapp.fragments.NewsFragment;

public class SectionsPagerAdapter extends FragmentPagerAdapter {

	private List<? extends BaseItem> newsItemList;
	public SectionsPagerAdapter(FragmentManager fm,List<? extends BaseItem> newsItemList) {
		super(fm);
		this.newsItemList = newsItemList;
	}

	@Override
	public Fragment getItem(int position) {
		// getItem is called to instantiate the fragment for the given page.
		// Return a DummySectionFragment (defined as a static inner class
		// below) with the page number as its lone argument.
		Fragment fragment = new NewsFragment();
		Bundle args = new Bundle();
		args.putSerializable(NewsFragment.ARG_NEWS_ITEM, newsItemList.get(position));
		fragment.setArguments(args);
		
		return fragment;
	}

	@Override
	public int getCount() {
		// Show 3 total pages.
		return newsItemList.size();
	}

	@Override
	public CharSequence getPageTitle(int position) {
		Log.i("Ravi - getPageTitle", newsItemList.get(position).getTitle() + " , position = "+position);
		return newsItemList.get(position).getTitle();
	}
}